//
//  JiNengTableViewCell.swift
//  RoundCatPlay2
//
//  Created by 姜澎 on 2019/10/29.
//  Copyright © 2019 jiangpeng. All rights reserved.
//

import UIKit

class JiNengTableViewCell: UITableViewCell {
    
    var jiNengModel: JinNengModel? {
        didSet {
            self.titleImag.image = UIImage(named: jiNengModel!.titleImage)
            self.titleL.text = jiNengModel?.titleName
            self.duanWeiLable.text = jiNengModel?.duanWei
            self.timesL.text = jiNengModel?.times
            self.money.text = jiNengModel?.money
        }
    }
    
    private lazy var titleImag:UIImageView = {
        let t = UIImageView()
        return t
    }()
    
    private lazy var titleL :UILabel = {
        let l = UILabel()
        l.font = UIFont.boldSystemFont(ofSize: 16)
        return l
    }()
    
    
    public lazy var duanWeiLable: UILabel = {
        let l = UILabel()
        l.textColor = .white
        l.font = UIFont.boldSystemFont(ofSize: 10)
        l.textAlignment = .center
        return l
    }()
    
    public lazy var duanWeiImage: UIImageView = {
        let i = UIImageView()
        i.image = UIImage(named: "blue")
        i.addSubview(self.duanWeiLable)
        return i
    }()
    
    private lazy var timesL: UILabel = {
        let t = UILabel()
        t.font = UIFont.systemFont(ofSize: 14)
        t.textColor = UIColor.darkGray
        t.sizeToFit()
        return t
    }()
    
    private lazy var bottomLine: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(red: 234/255, green: 234/255, blue: 234/255, alpha: 1)
        return v
    }()
    
    private lazy var money: UILabel = {
        var m = UILabel()
        
        m.font = UIFont.boldSystemFont(ofSize: 16)
        m.textColor = UIColor(red: 255.0 / 255.0, green: 162.0 / 255.0, blue: 0.0 / 255.0, alpha: 1)
        return m
    }()
    
    private lazy var xiaoShi: UILabel = {
        var l = UILabel()
        l.font = UIFont.systemFont(ofSize: 12)
        l.textColor = UIColor(red: 151.0 / 255.0, green: 151.0 / 255.0, blue: 151.0 / 255.0, alpha: 1.0)
        l.text = "/小时"
        return l
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        
    }

}

extension JiNengTableViewCell {
    func setUI(){
        addSubview(titleImag)
        addSubview(titleL)
        addSubview(timesL)
        addSubview(duanWeiImage)
        addSubview(money)
        addSubview(xiaoShi)
        addSubview(bottomLine)
        
        setTitleImageFrame()
        setTitleLFrame()
        setTimesLFrame()
        setDuanWeiImageFrame()
        setDuanWeiLableFraem()
        setMoneyFrame()
        setXiaoShi()
        setBottomLine()
    }
    
    func setTitleImageFrame(){
        self.titleImag.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.bottom.equalTo(-12)
            make.left.equalTo(23)
            make.width.equalTo(41)
            make.height.equalTo(41)
        }
    }
    
    func setTitleLFrame() {
        self.titleL.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleImag.snp_top).offset(0)
            make.left.equalTo(self.titleImag.snp_right).offset(17)
        }
    }
    
    func setTimesLFrame() {
        self.timesL.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleL.snp_bottom).offset(15)
            make.left.equalTo(self.titleL.snp_left)
            make.bottom.equalTo(self.titleImag.snp_bottom)
        }
    }
    
    func setDuanWeiImageFrame() {
        self.duanWeiImage.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleL.snp_top).offset(-2)
            make.left.equalTo(self.titleL.snp_right).offset(10)
            make.bottom.equalTo(self.titleL.snp_bottom).offset(2)
            
        }
    }
    
    func setDuanWeiLableFraem() {
        self.duanWeiLable.snp.makeConstraints { (make) in
            make.top.equalTo(7)
            make.right.equalTo(-7)
            make.bottom.equalTo(-7)
            make.left.equalTo(7)
        }
    }
    
    func setMoneyFrame() {
        self.money.snp.makeConstraints { (make) in
            
            make.centerY.equalTo(self.snp_centerY)
            make.right.equalTo(self.xiaoShi.snp_left)
        }
    }
    
    func setXiaoShi() {
        self.xiaoShi.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.snp_centerY)
            make.right.equalTo(-18)
        }
    }
    
    func setBottomLine() {
        self.bottomLine.snp.makeConstraints { (make) in
            make.left.equalTo(23)
            make.right.equalTo(-18)
            make.bottom.equalTo(0)
            make.height.equalTo(1)
        }
    }
    
}
